/*
 * MIT License
 *
 * Copyright (c) 2020 wen.gu <454727014@qq.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

/***************************************************************************
 * Name: cbus_endpoint.h
 *
 * Purpose: communication endpoint base module define
 *
 * Developer:
 *   wen.gu , 2021-06-15
 *
 * TODO:
 *
 ***************************************************************************/

/******************************************************************************
 **    INCLUDES
 ******************************************************************************/
#ifndef __CBUS_BUS_ENDPOINT_H__
#define __CBUS_BUS_ENDPOINT_H__

#include "cbus/core/cbus_type.h"
#include "cbus/core/cbus_error.h"
#include "cbus/core/cbus_buffer.h"
#include "cbus/bus/cbus_message_packet.h"
#include "cbus/bus/cbus_message_manager.h"
#include "cbus/bus/cbus_endpoint_ops.h"
/******************************************************************************
 **    MACROS
 ******************************************************************************/




/******************************************************************************
 **    TYPE DEFINITIONS
 ******************************************************************************/
G_C_HEADER_START


struct _cbus_endpoint;
typedef struct _cbus_endpoint* cbus_endpoint_t;

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////


/******************************************************************************
 **    CLASSES/FUNCTIONS DEFINITIONS
 ******************************************************************************/

G_API GErrc cbus_endpoint_create(cbus_endpoint_t* endpoint, cbus_endpoint_role role, const GSTR name, const GSTR url);

G_API void cbus_endpoint_destroy(cbus_endpoint_t endpoint);


G_API GErrc cbus_endpoint_start(cbus_endpoint_t endpoint);
G_API GErrc cbus_endpoint_stop(cbus_endpoint_t endpoint);


G_API GErrc cbus_endpoint_set_on_connect(cbus_endpoint_t endpoint, cbus_endpoint_on_connect_changed_func on_connect, GPTR opaque);

G_API GErrc cbus_endpoint_register_message(cbus_endpoint_t endpoint, const cbus_message_info_t* msg_info);
G_API GErrc cbus_endpoint_register_message_category(cbus_endpoint_t endpoint, cbus_message_type_t message_type, cbus_message_on_process_func on_message, GPTR opaque);
G_API GErrc cbus_endpoint_register_message_group(cbus_endpoint_t endpoint, const cbus_message_group_t* message_group);

G_API GErrc cbus_endpoint_unregister_message(cbus_endpoint_t endpoint, cbus_message_type_t message_type, cbus_message_id message_id);
G_API GErrc cbus_endpoint_unregister_message_category(cbus_endpoint_t endpoint, cbus_message_type_t message_type);
G_API GErrc cbus_endpoint_unregister_message_all(cbus_endpoint_t endpoint);

G_API GErrc cbus_endpoint_send(cbus_endpoint_t endpoint,  cbus_message_t message);



////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////


G_C_HEADER_END

#endif /** !__CBUS_BUS_ENDPOINT_H__ */

